package com.gl.emms.whale.ui;

import java.util.ArrayList;
import java.util.List;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

import com.gl.emms.whale.R;
import com.gl.emms.whale.adapter.GroupAdapter;
import com.gl.emms.whale.adapter.SettingAdapter;
import com.gl.emms.whale.app.WhaleMonitorActivity;
import com.gl.emms.whale.chart.MultipleTemperatureChart;
import com.gl.emms.whale.util.GroupEntity;
import com.gl.emms.whale.util.SettingEntity;
import com.gl.emms.whale.util.UpdateManager;

public class SettingActivity extends WhaleMonitorActivity implements
OnClickListener{
	private ListView mGroupListView ;
	private UpdateManager mUpdateManager;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);// 去掉标题栏
		setContentView(R.layout.activity_setting);

		//这里来检测版本是否需要更新
		mUpdateManager = new UpdateManager(this);

		mGroupListView = (ListView)findViewById(R.id.ListView_Setting);
		List<SettingEntity> groupList = new ArrayList<SettingEntity>();
		SettingEntity entity = new SettingEntity(0, "检查更新", 0);
		SettingEntity entity2 = new SettingEntity(0, "退出软件",0);
		SettingEntity entity3 = new SettingEntity(0, "关于我们",0);
		groupList.add(entity);
		groupList.add(entity2);
		groupList.add(entity3);
		SettingAdapter adapter = new SettingAdapter(this, groupList);
		mGroupListView.setAdapter(adapter);
		mGroupListView.setOnItemClickListener(new OnItemClickListener(){
			@Override
			public void onItemClick(AdapterView<?> arg0, View view,int position, long id) {
				// TODO Auto-generated method stub

				switch (position) {
				case 0://我的信息

					showChooseDownloadModeDialog();

					break;
				case 1://我的信息
					showToask("hehe ");					
					break;
				case 2://我的信息
					//showToask("hehe ");	
					Intent aboutSoftActivity = new Intent(SettingActivity.this,AboutSoftActivity.class);  
					startActivity(aboutSoftActivity);

					break;
				default:
					break;
				}


			}
		});
		Button titleBackBtn = (Button)findViewById(R.id.TitleBackBtn);  
		titleBackBtn.setOnClickListener(new OnClickListener() {  
			public void onClick(View v) {  
				KeyEvent newEvent = new KeyEvent(KeyEvent.ACTION_DOWN,  
						KeyEvent.KEYCODE_BACK);
				finish();
				//mActivity.onKeyDown(KeyEvent.KEYCODE_BACK, newEvent);  
			}  
		});
	}
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub

	}
	private void showChooseDownloadModeDialog(){
		Dialog noticeDialog;
		AlertDialog.Builder builder = new Builder(this);
		builder.setTitle("软件版本更新");
		builder.setMessage("选择下载方式");
		builder.setPositiveButton("软件自动下载", new AlertDialog.OnClickListener() {

			@Override
			public void onClick(DialogInterface dialog, int which) {
				dialog.dismiss();
				mUpdateManager.checkUpdateInfo();			
			}


		});
		builder.setNegativeButton("到浏览器下载", new AlertDialog.OnClickListener() {


			@Override
			public void onClick(DialogInterface dialog, int which) {
				dialog.dismiss();
				Uri uri = Uri.parse("http://pan.baidu.com/s/1dDktK6P");  
				startActivity(new Intent(Intent.ACTION_VIEW,uri));
			}


		});
		noticeDialog = builder.create();
		noticeDialog.show();
	}
}